<%@ Language=VBScript %>
<%
	Dim SecureOnly
	
	SecureOnly = True
	If SecureOnly Then
		If Request.ServerVariables("Server_Port_Secure")=0 Then
			Response.Write "This page can only be accessed via secure http.<br>"
			Response.End
		End If
	End If
%>

<HTML>
	<HEAD>
		<LINK rel="stylesheet" type="text/css" href="RAM.css">
		<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
		<title>Content Editor for RedemptoristRetreat.org</title>
		<SCRIPT LANGUAGE=javascript>
		<!--
			function EditorCommand(command) {
			   EditorDiv.focus();
			   EditorDiv.document.execCommand(command, false, null);
			   return false;
			}

			function EditorCommand2(command,bln,val) {
			   EditorDiv.focus();
			   EditorDiv.document.execCommand(command, bln, val);
			   return false;
			}
				  
			/*function ShowContents() {
			   window.alert(EditorDiv.innerHTML);
			}*/
			
			function SaveFile() {
				if (Form1.PageTitle.value==0) {
					window.alert("Please select a page to save.");
					return (false);
				}
				Form1.Content.value=EditorDiv.innerHTML;
				Form1.FileAction.value="Save";
				return (true);
			}
			
			function OpenFile() {
				if (Form1.PageTitle.value==0) {
					window.alert("Please select a page to open.");
					return (false);
				}
				Form1.FileAction.value="Open";	
			}
			
			function CheckContent() {
				if(Form1.Content.value.length>0) {
					EditorDiv.innerHTML=Form1.Content.value;
				}	
			}
		//-->
		</SCRIPT>
	</HEAD>
	<BODY onload="CheckContent();">
		<%
			Dim FileContents
			If Len(Request.Form)>0 Then
				'Response.Write Request.Form & "<BR>"
				FileContents=Request.Form("Content")
				If Len(Content)> 0 Then	FD=True
				
				FileAction = Request.Form("FileAction")
				PageTitle = Request.Form("PageTitle")
				SavePwd = Request.Form("SavePwd")
				
				Select Case PageTitle
					Case 1
						Filename="News.txt"
					Case 2
						Filename="Events.txt"
				End Select
				
				Select Case FileAction
					Case "Open"
						FileContents=""
						FileContents=GetFile(FileName) 
						'Response.Write "Here is the filename: " & FileName & "<br>"
						'Response.Write "Here are the contents: " & FileContents & "<br>"
					Case "Save"
						If SavePwd = "Majella" Then
							SaveFile FileName, FileContents
							Response.Write "<font color='green'>Document Saved.</font>"
						Else
							Response.Write "<font color='red'>Invalid Password, document not saved.</font>"
						End If
				End Select
				
			End If
			

			
			Function GetFile(FileName)
				Const ForReading = 1
				Dim fso, f
				Set fso = CreateObject("Scripting.FileSystemObject")
				Set f = fso.OpenTextFile(Server.MapPath(FileName), ForReading)
				Do While f.AtEndOfStream <> True
					FileContents =  FileContents & f.ReadLine
				Loop
				'Response.Write FileContents
				GetFile = FileContents
			End Function
			
			Sub SaveFile(FileName, FileContents)
				'Response.Write "Saving File<br>"
				Const ForWriting = 2
				Dim fso, f
				Set fso = CreateObject("Scripting.FileSystemObject")
				Set f = fso.OpenTextFile(Server.MapPath(FileName), ForWriting, True)
				f.Write FileContents
				Set f = Nothing
				Set fso = Nothing
			End Sub	
		%>
		<Form name="Form1" method=post action="Editor2.asp">
		<div name="PwordBar">
			Password:&nbsp;<input type=password name="Savepwd">
		</div>
		<div name="TopToolBar" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; WIDTH: 800px; BORDER-BOTTOM: 1px solid; HEIGHT: 30px; BACKGROUND-COLOR: #336666" align="center">
			<% Response.Write "<font size=1 color='white'>" & FileName & "</font>" %>
			<IMG onclick="return EditorCommand('Undo')" height=26 alt =Undo src="images\editor\Undo.gif" width=26 name=UndoCmd >
			<IMG onclick="return EditorCommand('Redo')" height=26 alt =Redo src="images\editor\Redo.gif" width=26 name=RedoCmd >
			<IMG onclick="return EditorCommand('JustifyLeft')" height=26 alt =Left src="images\editor\Left.gif" width=26 name=JustifyLeft >
			<IMG onclick="return EditorCommand('JustifyCenter')" height=26 alt =Center src="images\editor\Center.gif" width=26 name=JustifyCenter >
			<IMG onclick="return EditorCommand('JustifyRight')" height=26 alt =Right src="images\editor\Right.gif" width=26 name=JustifyCenter >
			<IMG onclick="return EditorCommand('Bold')" height=26 alt =Bold src="images\editor\Bold.gif" width=26 name=Bold >
			<IMG onclick="return EditorCommand('Italic')" height=26 alt =Italic src="images\editor\Italic.gif" width=26 name=Italic >
			<IMG onclick="return EditorCommand('Underline')" height=26 alt =Underline src="images\editor\Underline.gif" width=26 name=Underline >
			<IMG onclick="return EditorCommand2('InsertImage',true)" height=26 alt =image src="images\editor\Picture.gif" width=26 name=ImgButton >
			<IMG onclick="return EditorCommand2('CreateLink', true)" height  =26 alt=Hyperlink src="images\editor\Link.gif" width=26 name=WebLink >
			<IMG onclick="return EditorCommand('Unlink')" height=26 alt ="Remove Hyperlink" src="images\editor\Unlink.gif" width=26 name=UnWeblink >
          
			<select name="FontSize" onchange="return EditorCommand2('FontSize',false,FontSize.value)">
				<option value="1" selected>1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				<option value="4">4</option>
				<option value="5">5</option>
				<option value="6">6</option>
				<option value="7">7</option>
			</select>
		</div>
		<div name="EditorDiv" id="EditorDiv" contentEditable=true style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; WIDTH: 800px; BORDER-BOTTOM: 1px solid; FONT-FAMILY: Verdana; HEIGHT: 500px; BACKGROUND-COLOR: white">
		</div>
		<div name="BottomToolBar" align="center" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; WIDTH: 800px; BORDER-BOTTOM: 1px solid; BACKGROUND-COLOR: #336666">
			<input type="submit" value="Save" onclick="return SaveFile();">
			<input type="submit" value="Open" onclick="return OpenFile();" id=button1 name=button1>
			<%
				Dim PT(2)
				PT(0) = "--Select Page--"
				PT(1) = "News"
				PT(2) = "Events"
				
				Response.Write "<select name='PageTitle'>"
				For i=0 to 1
					Response.Write "<option value='" & i & "'"
					If CInt(PageTitle) = i Then Response.Write " selected"
					Response.Write ">" & PT(i) & "</option>"
				Next
				Response.Write "</select>"
					
			%>
			
			
			<!--
			<select name="PageTitle">
				<option value="0">Select Page</option>
				<option value="1">Novenas</option>
				<option value="2">Events</option>
			</select-->
			<!--input type="button" value="Preview" onclick="return ShowContents();"-->
			<input type="hidden" name="FileAction">
		</div>
		<div name="HiddenDiv" style="VISIBILITY: hidden">
			<%
				Response.Write "<textarea rows=1 cols=1 name='Content'>"
				Response.Write FileContents
				Response.Write "</textarea>"
			%>
		</div>
		</Form>
	</BODY>
</HTML>
